home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / UTILITIE / CONVERSI / 1396.ZIP / ANAG.C < prev    next >
C/C++ Source or Header  |  1988-01-12  |  1KB  |  57 lines

  1. ; ******************
  2. ; * Anagram Finder *
  3. ; * by Robin Nixon *
  4. ; * (C) PC Amstrad *
  5. ; ******************
  6. ;
  7. ; C source code listing
  8. ;
  9. #include "stdio.h"
  10.  
  11. int len, count=0, level=0;
  12. char string2[16], dummy[16]="               ";
  13.  
  14. main(argc,argv)
  15. int argc;
  16. char argv[];
  17. {
  18.         char string[16];
  19.  
  20.         if (argc < 2)
  21.         {
  22.                 printf("Use: ANAG word");
  23.                 exit();
  24.         }
  25.         len=strlen(argv[2]);
  26.         if (len > 15)
  27.         {
  28.                 printf("String too long (Max 15 characters)");
  29.                 exit();
  30.         }
  31.         strcpy(string,argv[2]) ;
  32.         strcpy(string2,argv[2]) ;
  33.         dummy[16-len]='\0';
  34.         sel(string);
  35. }
  36.  
  37. int sel(string)
  38. char *string;
  39. {
  40.         int j;
  41.         char s1[16];
  42.  
  43.         for (j=0 ; j<len ; ++j)
  44.         {
  45.                 strcpy(s1,string);
  46.                 if (s1[j] != ' ')
  47.                 {
  48.                         string2[level++]=s1[j];
  49.                         if (level == len)
  50.                                 printf("%s%s",string2,dummy);
  51.                         s1[j]=' ';
  52.                         sel(s1);
  53.                 }
  54.         }
  55.         --level;
  56. }
  57.